package com.example.administrator.tiyuapp.HeaderFragment;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;

import com.example.administrator.tiyuapp.R;
import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshListView;

import java.util.Timer;
import java.util.TimerTask;



/**
 * A simple {@link Fragment} subclass.
 */
public class HeaderFragment extends Fragment implements PullToRefreshBase.OnRefreshListener2 {


    public HeaderFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_header, container, false);

        PullToRefreshListView listView = (PullToRefreshListView) view.findViewById(R.id.fragment_header_listView);

        RelativeLayout emptyLayout = (RelativeLayout) view.findViewById(R.id.fragment_header_emptylayout);
        setProperty(listView, emptyLayout);  //ListView设置参数


        //显示空数据


        return view;
    }

    private void setProperty(PullToRefreshListView listView, RelativeLayout emptyLayout) {

        //设置ListView的模式 只支持下拉刷新
        listView.setMode(PullToRefreshBase.Mode.PULL_FROM_START);
        //设置监听
        listView.setOnRefreshListener(this);
        //设置空视图
        listView.setEmptyView(emptyLayout);
    }

    @Override
    public void onPullDownToRefresh(final PullToRefreshBase refreshView) {
        //下拉刷新

        new Timer().schedule(new TimerTask() {
            @Override
            public void run() {
                getActivity().runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        refreshView.onRefreshComplete();
                    }
                });
            }
        }, 2000);

    }

    @Override
    public void onPullUpToRefresh(PullToRefreshBase refreshView) {

    }
}
